package edu.bu.manateem.msg.analysis.io;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * Originally planned as Thread, but may be causing memory leaks.
 * So it's off for now.
 * @author yev
 *
 */
public class ChartPlotThread // extends Thread
{
	private static final String xAxisLabel = "Retention Time (seconds)";
	private static final String yAxisLabel = "Intensity";
	private static final int chartWidth = 1200;
	private static final int chartHeight = 800;
	
	private String compoundName;
	private XYSeriesCollection seriesData;
	private File destination;
	
	public ChartPlotThread(String compoundName,XYSeriesCollection seriesData,
		File destination)
	{
		this.compoundName = compoundName;
		this.seriesData = seriesData;
		this.destination = destination;
	}
	
	public void run()
	{
		JFreeChart chart =
			ChartFactory.createScatterPlot(compoundName,
				ChartPlotThread.xAxisLabel,ChartPlotThread.yAxisLabel,
				seriesData,PlotOrientation.VERTICAL,true,true,false);
		// JFreeChart chart =
		// ChartFactory.createHistogram(compoundName,
		// ChartPlotThread.xAxisLabel,ChartPlotThread.yAxisLabel,
		// seriesData,PlotOrientation.VERTICAL,true,true,false);
		try
		{
			ChartUtilities.saveChartAsJPEG(destination,chart,
				ChartPlotThread.chartWidth,ChartPlotThread.chartHeight);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
	}
}
